// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'yiibook-pro-yo19d'
})

// 云函数入口函数
exports.main = async (event, context) => {
  var result = await cloud.database().collection('exams').where({
    examDate: event.examDate
  }).get()
  var exams = result.data
  var taskList = []
  for(var i = 0; i < exams.length; i++) {
    var subscribe = await cloud.database().collection('subscribes').where({
      examId: exams[i]._id,
      openid: event.openid
    }).get()
    if(subscribe.data.length > 0) {
      taskList.push(exams[i])
    }
  }
  return taskList
}